<?php

require_once 'SmartL/Zend/Controller/Action.php';
require_once 'SmartL/Zend/Validate/ConfirmCredential.php';
require_once 'SmartL/Zend/Form.php';

class Admin_AuthorizationController extends SmartL_Zend_Controller_Action
{
    public function loginAction ()
    {
        if (Zend_Auth::getInstance()->hasIdentity()) {
            $this->_helper->redirector->gotoRoute(array("action"=>"list","controller"=>"products"),"admin");
        }
        
        $form = SmartL_Zend_Form::getForm($this->config->getAction("login")->getForm("login"), $this->translations['default']);
        $this->view->form = $form;

        if (isset($_POST['adminLogin']) and $form->isValid($_POST)) {
            if ( $form->password->getValue() == $this->application->getConfig()->demo->adminPassword->getValue() ) {
                Zend_Auth::getInstance()->getStorage()->write("admin");
                $this->_helper->redirector->goto("list", "products");
            }
            else {
            	$form->password->addError($this->translations['default']->translate('wrongPw'));
            }
        }               
    }
        
    public function logoutAction ()
    {
        if (Zend_Auth::getInstance()->hasIdentity()) {
            Zend_Auth::getInstance()->clearIdentity();
        }
        $this->_helper->redirector->goto('login', 'authorization');
    }
    public function accessDeniedAction ()
    {}
}

